export const arrToMap = (arr: any, key: string, valueKey?: string): object => {
  const result = Object.create(null)
  if (arr && arr.length) {
    valueKey ? arr.forEach(v => (result[v[key]] = v[valueKey])) : arr.forEach(v => (result[v[key] || v] = v))
  }
  return result
}

export const guid = () => {
  function s4() {
    return Math.floor((1 + Math.random()) * 0x10000)
      .toString(16)
      .substring(1)
  }
  // querySelector method uses CSS3 selectors for querying the DOM and CSS3
  // doesn't support ID selectors that start with a digit
  // for more:
  // https://stackoverflow.com/questions/37270787/uncaught-syntaxerror-failed-to-execute-queryselector-on-document
  return `cms-${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`
  // return `cms-${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`
}
